<?php

namespace App\Console\Commands;

use App\Events\BalanceChange;
use App\Events\BuyChange;
use App\Events\Kickout;
use App\Events\LoggedIn;
use App\Events\Login;
use App\Events\NoticeChange;
use App\Events\ProfileChange;
use App\Events\Sale;
use App\Events\SellChange;
use App\Events\Took;
use App\Jobs\BuyDone;
use App\Libs\Ucpaas;
use App\Models\Agency;
use App\Models\Balance;
use App\Models\Bankcard;
use App\Models\Seller;
use App\Models\Buy;
use App\Models\Member;
use App\Models\Sell;
use App\Models\System;
use App\Models\User;
use App\Models\Whitelist;
use Carbon\Carbon;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Crypt;

class MyTest extends Command
{
  /**
   * The name and signature of the console command.
   *
   * @var string
   */
  protected $signature = 'mytest';

  /**
   * The console command description.
   *
   * @var string
   */
  protected $description = 'Command description';

  /**
   * Create a new command instance.
   *
   * @return void
   */
  public function __construct()
  {
    parent::__construct();
  }

  /**
   * Execute the console command.
   *
   * @return int
   */
  public function handle()
  {
    $buys = Buy::take(2)->get();
    $buys = $buys->map(function ($buy) {

      return $buy->only('id', 'transaction_id', 'bank', 'bankcard', 'realname', 'coins');
    });

    dd($buys);
  }

  public function testSDK()
  {
    $buy = Buy::first();
    $buy->callback_url = 'http://106.13.74.212:9000/api/test';
    $buy->save();
    BuyDone::dispatch($buy);
  }
  public function testSms()
  {
    $ucpass = new Ucpaas([
      'accountsid' => 'caf12639bb65c3b0586b5bdb26ad91d5',
      'token' => 'b4e9687623375bef3bc40115106604b0'
    ]);

    $appid = "e0bb606ad1464031958758ce56bca93f";  //应用的ID，可在开发者控制台内的短信产品下查看
    $templateid = "609999";    //可在后台短信产品→选择接入的应用→短信模板-模板ID，查看该模板ID
    $code = random_int(1000, 9999);
    $param = "{$code},60";
    $mobile = '13797528120';
    // $mobile = '13249178867';
    $uid = "";

    //70字内（含70字）计一条，超过70字，按67字/条计费，超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。
    $msg = $ucpass->SendSms($appid, $templateid, $param, $mobile, $uid);

    dd($msg);
  }

  public function testGa()
  {
    $ga = new \PHPGangsta_GoogleAuthenticator();
    $secret = $ga->createSecret();
    echo "Secret is: " . $secret . "\n\n";


    $qrCodeUrl = $ga->getQRCodeGoogleUrl('Blog', $secret);
    echo "Google Charts URL for the QR-Code: " . $qrCodeUrl . "\n\n";

    $oneCode = $ga->getCode($secret);
    echo "Checking Code '$oneCode' and Secret '$secret':\n";

    $checkResult = $ga->verifyCode($secret, $oneCode, 2);    // 2 = 2*30sec clock tolerance
    if ($checkResult) {
      echo 'OK';
    } else {
      echo 'FAILED';
    }
  }
}
